<?php

use think\migration\Migrator;
use think\migration\db\Column;

class ThisIsDemo extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        //表支持的参数选项
        //选项	        描述
        //comment	    给表结构设置文本注释
        //row_format	设置行记录模格式
        //engine	    表引擎 (默认 InnoDB)
        //collation	    表字符集 (默认 utf8\_general\_ci)
        //signed	    是否无符号 signed(默认 true)

        //常用列
        //biginteger
        //binary
        //boolean
        //date
        //datetime
        //decimal
        //float
        //integer
        //string
        //text
        //time
        //timestamp
        //uuid

        //所有的类型都支持的参数
        //Option	Description
        //limit	    文本或者整型的长度
        //length	limit别名
        //default	默认值
        //null	    允许 NULL 值 (不该给主键设置
        //after	    在哪个字段名后 (只对MySQL有效)
        //comment	给列设置文本注释

        //索引的用法
        //      ->addIndex(['email','username'], ['limit' => ['email' => 5, 'username' => 2]])
        //      ->addIndex('user_guid', ['limit' => 6])
        //      ->addIndex('email',['type'=>'fulltext'])

        $table  =  $this->table('Demo',array('engine'=>'MyISAM'));
        $table->addColumn('username', 'string',array('limit'  =>  15,'default'=>'','comment'=>'用户名，登陆使用'))
            ->addColumn('password', 'string',array('limit'  =>  32,'default'=>md5('123456'),'comment'=>'用户密码'))
            ->addColumn('login_status', 'boolean',array('limit'  =>  1,'default'=>0,'comment'=>'登陆状态'))
            ->addColumn('login_code', 'string',array('limit'  =>  32,'default'=>0,'comment'=>'排他性登陆标识'))
            ->addColumn('last_login_ip', 'integer',array('limit'  =>  11,'default'=>0,'comment'=>'最后登录IP'))
            ->addColumn('last_login_time', 'datetime',array('default'=>0,'comment'=>'最后登录时间'))
            ->addColumn('is_delete', 'boolean',array('limit'  =>  1,'default'=>0,'comment'=>'删除状态，1已删除'))
            ->addIndex(array('username'), array('unique'  =>  true))
            ->create();
    }

    /**
     * Migrate Up.
     * 升级方法
     */
    public function up()
    {

    }

    /**
     * Migrate Down.
     * 降级方法
     */
    public function down()
    {

    }
}
